package com.example.superoa.interceptor;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.redirectedUrl;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import com.example.superoa.model.vo.LoginVo;

@Component
public class UserLoginInterceptor implements HandlerInterceptor{
	
/*	public boolean perHandle(HttpServletRequest request,HttpServletResponse response) {
		HttpSession session = request.getSession();
		Basic user=(Basic)session.getAttribute("user");
		
		if(user==null) {
			
			return false;
		}else {
			return true;
		}
				
	}*/
	@Override
	public void afterCompletion(HttpServletRequest arg0, HttpServletResponse arg1, Object arg2, Exception arg3)
			throws Exception {
	}
 
	@Override
	public void postHandle(HttpServletRequest request, HttpServletResponse arg1, Object arg2, ModelAndView arg3)
			throws Exception {
	}
 
	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object arg2) throws Exception {
		HttpSession session = request.getSession();
		LoginVo staff=(LoginVo)session.getAttribute("staff");
		String sfzz=(String) session.getAttribute("yhusfzz");
		System.out.println("staff=="+staff+"----"+sfzz);
		if(staff==null) {
			response.sendRedirect("login");
			return false;
		}else if(sfzz.equals("否")){
			return false;
		}else {
			return true;
		}
		//只有返回true才会往下执行，返回FALSE的话就会取消当前请求
	}
}

